package pl.edu.agh.winmon.hibernate;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Represents program that has been launched during session.
 */
@Entity
@Table(name = "`" + Program.TABLE_NAME + "`")
public class Program implements Serializable {

	@Transient
	private static final long serialVersionUID = 844149738605003948L;

	/**
	 * Table name.
	 */
	@Transient
	public static final String TABLE_NAME = "program"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: id.
	 */
	@Transient
	public static final String PROP_ID = "id"; //$NON-NLS-1$

	/**
	 * Database column name: id;
	 */
	@Transient
	public static final String DB_ID = PROP_ID;

	/**
	 * Hibernate's annotation property: session id.
	 */
	@Transient
	public static final String PROP_SESSION = "session"; //$NON-NLS-1$

	/**
	 * Database column name: session id;
	 */
	@Transient
	public static final String DB_SESSION = "session_id"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: program's name.
	 */
	@Transient
	public static final String PROP_NAME = "name"; //$NON-NLS-1$

	/**
	 * Database column name: program's name;
	 */
	@Transient
	public static final String DB_NAME = PROP_NAME;
	
	/**
	 * Hibernate's annotation property: processes.
	 */
	@Transient
	public static final String PROP_PROCESSES = "processes"; //$NON-NLS-1$

	/**
	 * Id.
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = DB_ID)
	private Long id;

	/**
	 * Session during which this program has been launched.
	 */
	@ManyToOne
	@JoinColumn(name = DB_SESSION)
	private Session session;

	/**
	 * Program's name.
	 */
	@Column(name = DB_NAME)
	private String name;
	
	/**
	 * Processes related to this program.
	 */
	@OneToMany(mappedBy = TABLE_NAME)
	@OrderColumn(name = Process.PROP_ID)
	private List<Process> processes;

	/**
	 * Returns Id.
	 * 
	 * @return Id.
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Sets Id.
	 * 
	 * @param id
	 *            Id.
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Returns session during which this program has been launched.
	 * 
	 * @return Session during which this program has been launched.
	 */
	public Session getSession() {
		return session;
	}

	/**
	 * Sets session during which this program has been launched.
	 * 
	 * @param session
	 *            Session during which this program has been launched.
	 */
	public void setSession(Session session) {
		this.session = session;
	}

	/**
	 * Returns program's name.
	 * 
	 * @return Program's name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets program's name.
	 * 
	 * @param name
	 *            Program's name.
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Returns processes related to this program.
	 * 
	 * @return Processes related to this program.
	 */
	public List<Process> getProcesses() {
		return processes;
	}

	/**
	 * Sets processes related to this program.
	 * 
	 * @param processes
	 *            Processes related to this program.
	 */
	public void setProcesses(List<Process> processes) {
		this.processes = processes;
	}
}
